package com.zj.leetcode.easy.greed;

/**
 * @program: algorithm
 * @description:
 * 种花问题
 * 605 can-place-flowers
 * @author: Zhang Bo
 * @create: 2022-01-14 17:05
 **/
public class CanPlaceFlowers{
    public static void main(String[] args) {
        int[] nums = {1,0,0,0,0,1};
        int n = 2;

//        int[] nums = {0,0,1,0,1};
//        int n = 1;
        Solution solution = new CanPlaceFlowers().new Solution();
        System.out.println(solution.canPlaceFlowers(nums, n));
    }
    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public boolean canPlaceFlowers(int[] flowerbed, int n) {

            int bucket = 1;
            int count = 0;
            int length = flowerbed.length;
            for (int i = 0; i < length; i++) {
                if(flowerbed[i] == 0){
                    bucket++;
                    if(bucket > 1){
                        if(i == length - 1 || flowerbed[i + 1] != 1){
                            count++;
                        }
                        bucket = 0;
                    }
                } else {
                    bucket = 0;
                }
            }
            return count >= n;

        }
    }
//leetcode submit region end(Prohibit modification and deletion)

}
